<template>
	<view>

<uni-list>
	<uni-list :border="true">
		<view class="" style="display: flex; margin-top: 3%;">
				<button type="primary" style="background: #4e72d5;" @tap="loadPostsByType('zczx')">政策咨询</button>
				<button type="primary" style="background: #4e72d5;"  @tap="loadPostsByType('yjfk')">意见反馈</button>
<!-- 				<button type="primary" style="background: #00aa7f; width: 20%;" @tap="loadPostsByType('knfy')">困难反映</button> -->
				<button type="primary" style="background: #4e72d5;" @tap="loadPostsByType('jjkg')">监督举报</button>				
		</view>
		<!-- 显示圆形头像 -->
		<uni-list-item  v-for="(item, index) in list" :key="index" :title="item.title" :note="item.user_info.nick_name" :rightText="item.date"  clickable  @click="toDetail(item)" showArrow :thumb="
item.reply==''?'https://mp-40cfdf28-d8fa-4dc1-a8f9-a7a30a1a9419.cdn.bspapp.com/办理中.png':'https://mp-40cfdf28-d8fa-4dc1-a8f9-a7a30a1a9419.cdn.bspapp.com/完成.png'"
					thumb-size="sm"></uni-list-item>
		<!-- 右侧带角标 -->
<!-- 		<uni-list-item  v-for="(item, index) in list" :key="index" :title="item.title" :note="item.user_info.nick_name" :rightText="item.date"  clickable  @click="toDetail(item)" showArrow thumb="https://mp-40cfdf28-d8fa-4dc1-a8f9-a7a30a1a9419.cdn.bspapp.com/办理中.png"
					thumb-size="sm"></uni-list-item> -->
	</uni-list>
</uni-list>


<!-- 		<view  v-for="(item, index) in list" :key="index">
			<text>{{item.title}}</text>
			<text>{{item.author}}</text>
			<text>{{item.date}}</text>
		</view> -->
		<loading
			ref="loading"
			:custom="false"
			:shadeClick="true"
			:type="1"
			>
			<view style="text-align: center;">等待中</view>
		</loading>
	</view>
</template>
<script>
	import loading from '@/components/xuan-loading/xuan-loading.vue'
	export default {
		components: {
			loading
		  },
		async mounted() {
			
			let value = uni.getStorageSync('user_info');
			let user_id=value._id
			
			let a=await this.loadPostsByType('zczx')
			//let a= await this.getPostsByUserId(user_id)
		},
		data() {
			return {
				list:[],
				type_str:'政策咨询'
			}
		},
		methods: {
			toDetail(item){
				uni.navigateTo({
					url:"/pages/postDetail2/postDetail2?item="+encodeURIComponent(JSON.stringify(item))+"&type_name="+this.type_str
				})
			},
			getPostsByUserId(id){
				uniCloud.callFunction({
					name: 'getPostsByUserId',
					data: {
							"user_id":id,
					}
				})
				.then(res => {
					let result=res.result
					this.list=result.list
					this.$refs.loading.close();
				});
			
			},
			loadPostsByType(type){
				if(type=='zczx'){
					this.type_str='政策咨询'
				}else if(type=='yjfk'){
					this.type_str='意见反馈'
				}else if(type=='jjkg'){
					this.type_str='监督举报'
				}
				console.log(this.type_str)
				this.$refs.loading.open();
				uniCloud.callFunction({
					name: 'getPostsByType',
					data: {
						"type":type
					}
				  })
				  .then(res => {
					  console.log(res)
					let result=res.result
					this.list=result.list
					this.$refs.loading.close();
				  });					
			},
			loadPost(){
				this.$refs.loading.open();
				uniCloud.callFunction({
					name: 'getPosts',
					data: {
						"page":0
					}
				  })
				  .then(res => {
					  console.log(res)
					let result=res.result
					this.list=result.list
					this.$refs.loading.close();
				  });				
			}
		}
	}
</script>

<style scoped>
	.chat-custom-right {
		flex: 1;
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
		justify-content: space-between;
		align-items: flex-end;
	}

	.chat-custom-text {
		font-size: 12px;
		color: #999;
	}

</style>